/**
 * Control de 4 direcciones. Controla arruba, abajo, izq y derecha.
 * @GameObject {GameObject} - objeto a controlar
 * @aNameUp {String} - id de animacion hacia arriba
 * @aNameRight {String} - id de animacion hacia derecha
 * @aNameDown {String} - id de animacion hacia abajo
 * @aNameLeft {String} - id de animacion hacia izquierda
 */
SimpleController4Axis = function(gameObject, aNameUp, aNameRight, aNameDown, aNameLeft, runSpeedX, runSpeedY) {
    Controller.call(this, gameObject);

    aNameUp = aNameUp || "walk_u";
    aNameRight = aNameRight || "walk_r";
    aNameLeft = aNameLeft || "walk_l";
    aNameDown = aNameDown || "walk_d";

    this.animationNames = {
        "right": aNameRight,
        "left": aNameLeft,
        "down": aNameDown,
        "up": aNameUp
    };

    this.runSpeedX = runSpeedX;
};

SimpleController4Axis.prototype = Object.create(Controller.prototype);


SimpleController4Axis.prototype.run = function() {
    if (this.onDebug)
        this.onDebug();


    var foundInputX = false;
    var foundInputY = false;

    var go = this.gameObject;
    var an = this.animationNames;
    var nextAn = null;

    var runSpeedX = this.runSpeedX || go.speedX;
    var runSpeedY = this.runSpeedY || go.speedY;

    if (input.left) {
        go.vx = -runSpeedX;
        nextAn = an.left;
        foundInputX = true;
    } else if (input.right) {
        this.gameObject.vx = runSpeedX;
        nextAn = an.right;
        foundInputX = true;
    }

    if (input.up) {
        this.gameObject.vy = -runSpeedY;
        nextAn = an.up;
        foundInputY = true;
    } else if (input.down) {
        this.gameObject.vy = runSpeedY;
        nextAn = an.down;
        foundInputY = true;
    }

    if (!foundInputX) {
        this.gameObject.vx = 0;
    }

    if (!foundInputY) {
        this.gameObject.vy = 0;
    }

    if (nextAn) {
        if (this.gameObject.currAnimationName != nextAn) {
            this.gameObject.animation.gotoAndPlay(nextAn);
            this.gameObject.currAnimationName = nextAn;
        }
    }
    /*    this.gameObject.move(this.gameObject.vx, this.gameObject.vy);*/
};
//run
